﻿using PLCCommunication;
using System.Threading.Tasks;

namespace PLC
{
    /// <summary>
    /// PLC接口
    /// </summary>
    public interface IPLC
    {
        /// <summary>
        /// 链接
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        bool Connect(ref string msg);
        /// <summary>
        /// 断开
        /// </summary>
        /// <returns></returns>
        bool Disconnect();

        #region 读取
        /// <summary>
        /// 读取单个Bool
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        bool ReadBool(string address);
        /// <summary>
        /// 读取单个Int16整数
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        short ReadInt16(string address);
        /// <summary>
        /// 异步读取单个Int16整数
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        Task<JYResult<short>> ReadInt16Async(string address);
        /// <summary>
        /// 读取Int16数组
        /// </summary>
        /// <param name="address"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        short[] ReadArrInt16(string address, ushort length);
        /// <summary>
        /// 异步读取Int16数组
        /// </summary>
        /// <param name="address"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        Task<JYResult<short[]>> ReadArrInt16Async(string address, ushort length);
        /// <summary>
        /// 读取单个32位整数
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        int ReadInt32(string address);
        /// <summary>
        /// 异步读取单个32位整数
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        Task<JYResult<int>> ReadInt32Async(string address);
        /// <summary>
        /// 读取浮点型数据
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        float ReadFloat(string address);
        /// <summary>
        /// 异步读取float数组
        /// </summary>
        /// <param name="address"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        Task<JYResult<float[]>> ReadArrFloatAsync(string address, ushort length);

        /// <summary>
        /// 泛型读取
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="address"></param>
        /// <param name="type"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        T ReadValue<T>(string address, DataType type, ushort length = 0);

        #endregion

        #region 写入
        bool WriteBool(string address, bool value);
        bool WriteInt16(string address, short value);
        bool WriteInt32(string address, int value);
        bool WriteFloat(string address, float value);
        JYResult WriteValue(string address, object value, PLC.DataType type);
        #endregion
    }
}
